/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.gerenciadoc.mb;

import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import javax.servlet.http.HttpSession;

/**
 *
 * @author pedrogazzola
 */
public class Utilitario {

    public static HttpSession getHttpSession() {
        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
        HttpSession s = (HttpSession) externalContext.getSession(true);
        return s;
    }

    public static void setHttpSessionObject(String campo, Object o) {
        getHttpSession().setAttribute(campo, o);
    }

    public static Object getHttpSessionObject(String campo) {
        return getHttpSession().getAttribute(campo);
    }

    public static void genericShowMessage(String mensagem) {
        FacesMessage message = new FacesMessage(mensagem);
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(message);
    }
}
